package com.qf.j2105.attendance.controller;

import com.qf.j2105.attendance.service.PunchingService;
import com.qf.j2105.po.PunchingRecord;
import com.qf.j2105.vo.ActionResult;
import com.qf.j2105.vo.PunchingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
public class PunchingController {
    @Autowired
    private PunchingService punchingService;
    //打卡功能
    @RequestMapping(value = "/punching",method = RequestMethod.POST)
    public ActionResult punching(@RequestBody PunchingVO punchingVO){
        Date date = punchingVO.getDate();
        Integer eid = punchingVO.getEid();
        if(date!=null&&eid!=null){
            boolean b = punchingService.addPuching(date, eid);
            if (b){
                return new ActionResult(200,"","ok");
            }
        }
        return new ActionResult(500,"","打卡失败");
    }
    //查询打卡记录功能
    @RequestMapping(value = "/findPunching")
    public ActionResult findPunching(Date date,Integer eid){
        List<PunchingRecord> list = punchingService.findPunchingRecordByDay(eid, date);
        if (date!=null&&eid!=null){
            return new ActionResult(200,"",list);
        }
        return new ActionResult(500,"",null);
    }
}
